def add(x, y):
    """加法"""
    return x + y

def subtract(x, y):
    """减法"""
    return x - y

def multiply(x, y):
    """乘法"""
    return x * y

def divide(x, y):
    """除法"""
    if y == 0:
        return "错误:除数不能为0"
    return x / y

def calculator():
    """主函数,用于处理用户输入和调用运算"""

    num1 = float(input("输入第一个数字: "))

    print("选择运算:+-,*,/")
    # print("+")
    # print("-")
    # print("*")
    # print("/")
    
    choice = input("输入你的运算符号: ")

    num2 = float(input("输入第二个数字: "))

    if choice == '+':
        print(num1, "+", num2, "=", add(num1, num2))

    elif choice == '-':
        print(num1, "-", num2, "=", subtract(num1, num2))

    elif choice == '*':
        print(num1, "*", num2, "=", multiply(num1, num2))

    elif choice == '/':
        result = divide(num1, num2)
        if isinstance(result, str):
            print(result)
        else:
            print(num1, "/", num2, "=", result)

    else:
        print("非法输入")

# 调用函数
calculator()